package app.quiz;

import app.quiz.util.Constants;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * User: Georgiana.Scarlat
 * Date: 8/14/12
 * Time: 11:39 AM
 */
public class TimeServlet extends GenericPatternServlet {


    @Override
    protected void setHtmlFileName() {
        htmlFileName = "timeTemplate.html";
    }

    @Override
    protected boolean doSomeInitialProcessing(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setIntHeader("Refresh", 1);
        return true;
    }

    @Override
    protected void fillInHTMLTemplate(HttpServletRequest request, HttpServletResponse response) {

        htmlTemplate.removeAttribute(Constants.TIME);
        htmlTemplate.setAttribute(Constants.TIME, HomeServlet.elapsedTime);

        if (HomeServlet.elapsedTime > 0)
            HomeServlet.elapsedTime--;

    }

}
